import {createSlice} from "@reduxjs/toolkit";
import {request} from "@/utils";

const userStore = createSlice({
    name: 'user',
    initialState: {
        token: null,
    },
    reducers: {
        setToken: (state, action) => {
            state.token = action.payload;
        }
    }
})
const fetchLogin = (loginForm) => {
    return async dispatch => {
        const res = await request.post('/authorizations', loginForm);
        dispatch(setToken(res.data.token));
    }
}




const {setToken} = userStore.actions;

const userReducer = userStore.reducer

export {setToken,fetchLogin};

export default userReducer;